# ===== Cell 1 (code) =====
#S12

username = input("Enter username: ")
password = input("Enter password: ")

# Educational simulation using local file
with open("demo_login.txt", "w") as file:
    file.write("Username: " + username + "\n")
    file.write("Password: " + password)

print("Demo login details saved.")

# ===== Cell 2 (code) =====
#S22

email = input("Enter email message: ")

words = ["win", "free", "offer", "prize", "lottery"]

spam = False

for word in words:
    if word in email.lower():
        spam = True

if spam:
    print("Spam Email")
else:
    print("Not Spam")

# ===== Cell 3 (code) =====
#S33

print("===== Phishing Awareness Demo =====")

username = input("Enter a demo username: ")
password = input("Enter a demo password: ")

print("\n⚠️ WARNING!")
print("This was only an educational simulation.")
print("Never enter real passwords on unknown websites.")
print("Always check the website URL before logging in.")

# ===== Cell 4 (code) =====
#S43

# Password Strength Checker

password = input("Enter password: ")

if len(password) < 8:
    print("Password is Weak")
elif password.isalpha():
    print("Password is Weak")
elif password.isdigit():
    print("Password is Weak")
elif password.isalnum():
    print("Password is Medium")
else:
    print("Password is Strong")

# ===== Cell 5 (code) =====
#S52

# IP Tracking Simulation

ip_address = {
    "192.168.1.1": "Pune",
    "192.168.1.2": "Mumbai",
    "192.168.1.3": "Delhi",
    "192.168.1.4": "Nashik"
}

ip = input("Enter IP address: ")

if ip in ip_address:
    print("IP Address:", ip)
    print("Location:", ip_address[ip])
else:
    print("IP address not found")

# ===== Cell 6 (code) =====
#S62

password = input("Enter password: ")

has_digit = False
has_special = False

for ch in password:
    if ch.isdigit():
        has_digit = True
    elif not ch.isalnum():
        has_special = True

if len(password) >= 8 and has_digit and has_special:
    print("Strong Password")
else:
    print("Weak Password")

# ===== Cell 7 (code) =====
#S73

text = input("Enter text: ")
shift = int(input("Enter shift: "))

# Encryption
encrypted = ""

for ch in text:
    if ch.isalpha():
        encrypted += chr((ord(ch.upper()) - 65 + shift) % 26 + 65)
    else:
        encrypted += ch

print("Encrypted text:", encrypted)

# Decryption
decrypted = ""

for ch in encrypted:
    if ch.isalpha():
        decrypted += chr((ord(ch) - 65 - shift) % 26 + 65)
    else:
        decrypted += ch

print("Decrypted text:", decrypted)

# ===== Cell 8 (code) =====
#S83

passwords = ["123456", "password", "admin", "welcome", "qwerty"]

target = input("Enter target password: ")

if target in passwords:
    print("Password found in dictionary!")
else:
    print("Password not found in dictionary.")

# ===== Cell 9 (code) =====
#S83

passwords = ["123456", "password", "admin", "welcome", "qwerty"]

target = input("Enter target password: ")

if target in passwords:
    print("Password found in dictionary!")
else:
    print("Password not found in dictionary.")

# ===== Cell 10 (code) =====


# ===== Cell 11 (code) =====
#S92

from Crypto.Cipher import AES

key = b"1234567890123456"
message = b"HELLO WORLD"

# Add padding
message = message + b" " * (16 - len(message) % 16)

# Encryption
cipher = AES.new(key, AES.MODE_ECB)
encrypted = cipher.encrypt(message)

print("Encrypted:", encrypted)

# Decryption
cipher = AES.new(key, AES.MODE_ECB)
decrypted = cipher.decrypt(encrypted)

print("Decrypted:", decrypted.decode().strip())

# ===== Cell 12 (code) =====
#S102

from Crypto.Cipher import AES

key = b"1234567890123456"

message = input("Enter message: ").encode()

# Add padding
message = message + b" " * (16 - len(message) % 16)

# Encryption
cipher = AES.new(key, AES.MODE_ECB)
encrypted = cipher.encrypt(message)

print("Encrypted message:", encrypted)

# Decryption
cipher = AES.new(key, AES.MODE_ECB)
decrypted = cipher.decrypt(encrypted)

print("Decrypted message:", decrypted.decode().strip())

# ===== Cell 13 (code) =====
#S113


from scapy.all import sniff, IP

count = {}
limit = 10

def check_packet(packet):
    if IP in packet:
        ip = packet[IP].src

        if ip in count:
            count[ip] += 1
        else:
            count[ip] = 1

        print(ip, ":", count[ip])

        if count[ip] > limit:
            print("ALERT! Possible DoS attack from", ip)

print("Monitoring packets...")

sniff(prn=check_packet, count=50)

# ===== Cell 14 (code) =====
#S123

p = 3
q = 11
e = 7
M = 5

n = p * q

phi = (p - 1) * (q - 1)

# Private key
d = 3

# Encryption
C = (M ** e) % n

# Decryption
D = (C ** d) % n

print("n =", n)
print("phi =", phi)
print("Private key d =", d)
print("Encrypted message =", C)
print("Decrypted message =", D)

# ===== Cell 15 (code) =====
#S123

p = 3
q = 11
e = 7
M = 5

n = p * q

phi = (p - 1) * (q - 1)

# Private key
d = 3

# Encryption
C = (M ** e) % n

# Decryption
D = (C ** d) % n

print("n =", n)
print("phi =", phi)
print("Private key d =", d)
print("Encrypted message =", C)
print("Decrypted message =", D)

# ===== Cell 16 (code) =====
#S131

text = input("Enter message: ")
shift = 3

encrypted = ""

for ch in text:
    if ch.isalpha():
        encrypted = encrypted + chr((ord(ch.upper()) - 65 + shift) % 26 + 65)
    else:
        encrypted = encrypted + ch

print("Encrypted message:", encrypted)

# ===== Cell 17 (code) =====
#S133

from Crypto.Cipher import AES

key = input("Enter 16 character key: ").encode()
message = input("Enter message: ").encode()

# Add padding
message = message + b" " * (16 - len(message) % 16)

# Encryption
cipher = AES.new(key, AES.MODE_ECB)
encrypted = cipher.encrypt(message)

print("Encrypted message:", encrypted)

# Decryption
cipher = AES.new(key, AES.MODE_ECB)
decrypted = cipher.decrypt(encrypted)

print("Decrypted message:", decrypted.decode().strip())

# ===== Cell 18 (code) =====
#S143

text = input("Enter text: ")

print("Character\tASCII Value")

for ch in text:
    print(ch, "\t\t", ord(ch))

# ===== Cell 19 (code) =====
#S153

ip_location = {
    "192.168.1.1": "Pune",
    "192.168.1.2": "Mumbai",
    "192.168.1.3": "Delhi",
    "192.168.1.4": "Nashik"
}

ip = input("Enter IP address: ")

if ip in ip_location:
    print("IP Address:", ip)
    print("Location:", ip_location[ip])
else:
    print("IP address not found")

# ===== Cell 20 (code) =====
#S162

text = input("Enter message: ")
shift = 3

encrypted = ""

for ch in text:
    if ch.isalpha():
        encrypted = encrypted + chr((ord(ch.upper()) - 65 + shift) % 26 + 65)
    else:
        encrypted = encrypted + ch

print("Encrypted message:", encrypted)

# ===== Cell 21 (code) =====
#S172

packets = [
    "Hello user",
    "Enter password here",
    "Welcome to website",
    "Your PIN is required"
]

keywords = ["password", "pin"]

for packet in packets:
    print("Packet:", packet)

    for word in keywords:
        if word.lower() in packet.lower():
            print("ALERT! Sensitive keyword detected:", word)

# ===== Cell 22 (code) =====
#S182

text = input("Enter a sentence: ")
shift = 3

encrypted = ""

for ch in text:
    if ch.isalpha():
        if ch.isupper():
            encrypted = encrypted + chr((ord(ch) - 65 + shift) % 26 + 65)
        else:
            encrypted = encrypted + chr((ord(ch) - 97 + shift) % 26 + 97)
    else:
        encrypted = encrypted + ch

print("Encrypted sentence:", encrypted)

# ===== Cell 23 (code) =====
#S192

text = input("Enter a sentence: ")
shift = 3

encrypted = ""

for ch in text:
    if ch.isalpha():
        if ch.isupper():
            encrypted = encrypted + chr((ord(ch) - 65 + shift) % 26 + 65)
        else:
            encrypted = encrypted + chr((ord(ch) - 97 + shift) % 26 + 97)
    else:
        encrypted = encrypted + ch

print("Encrypted sentence:", encrypted)

# ===== Cell 24 (code) =====
#S203

text = input("Enter text: ")

print("Character\tASCII Value")

for ch in text:
    print(ch, "\t\t", ord(ch))

# ===== Cell 25 (code) =====
#S213

from Crypto.Cipher import AES

key = b"1234567890123456"

text = input("Enter plaintext: ")

# Convert text to bytes
text = text.encode()

# Add padding
text = text + b" " * (16 - len(text) % 16)

# AES Encryption
cipher = AES.new(key, AES.MODE_ECB)
encrypted = cipher.encrypt(text)

print("Encrypted text:", encrypted)

# ===== Cell 26 (code) =====
#S223

password = input("Enter password: ")

has_digit = False
has_special = False

for ch in password:
    if ch.isdigit():
        has_digit = True
    elif not ch.isalnum():
        has_special = True

if len(password) >= 8 and has_digit and has_special:
    print("Strong Password")
else:
    print("Weak Password")

# ===== Cell 27 (code) =====
#S233

print("===== Phishing Awareness Demo =====")

username = input("Enter demo username: ")
password = input("Enter demo password: ")

print("\nLogin Page Simulation")
print("Username entered:", username)
print("Password received: [HIDDEN]")

print("\nWARNING!")
print("This is an educational phishing simulation.")
print("Never enter your real password on an unknown website.")

# ===== Cell 28 (code) =====
#S242

# IP Tracking Simulation

ip_location = {
    "192.168.1.1": "Pune",
    "192.168.1.2": "Mumbai",
    "192.168.1.3": "Delhi",
    "192.168.1.4": "Nashik"
}

ip = input("Enter IP address: ")

if ip in ip_location:
    print("IP Address:", ip)
    print("Location:", ip_location[ip])
else:
    print("IP address not found")

# ===== Cell 29 (code) =====
#S253

print("===== Phishing Awareness Demo =====")

username = input("Enter demo username: ")
password = input("Enter demo password: ")

print("\nLogin Page Simulation")
print("Username:", username)
print("Password: [HIDDEN]")

print("\nWARNING!")
print("This was an educational phishing simulation.")
print("Never enter your real password on unknown websites.")

# ===== Cell 30 (code) =====
#S261

text = input("Enter encrypted message: ")
shift = 3

decrypted = ""

for ch in text:
    if ch.isalpha():
        if ch.isupper():
            decrypted = decrypted + chr((ord(ch) - 65 - shift) % 26 + 65)
        else:
            decrypted = decrypted + chr((ord(ch) - 97 - shift) % 26 + 97)
    else:
        decrypted = decrypted + ch

print("Decrypted message:", decrypted)

# ===== Cell 31 (code) =====
#S262

# RSA Algorithm

p = 3
q = 11

# Calculate n
n = p * q

# Calculate phi
phi = (p - 1) * (q - 1)

# Public key
e = 3

# Private key
d = 7

# Message
message = 5

# Encryption
encrypted = (message ** e) % n

# Decryption
decrypted = (encrypted ** d) % n

print("Public Key:", (e, n))
print("Private Key:", (d, n))
print("Original Message:", message)
print("Encrypted Message:", encrypted)
print("Decrypted Message:", decrypted)

# ===== Cell 32 (code) =====

